#include <bits/stdc++.h>
using namespace std;
#include <atcoder/segtree>
using namespace atcoder;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int a[N];

int op(int a, int b) { return max(a, b); }
int e() { return -1; }
int target;
bool f(int v) { return v < target; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  vector<int> a(n);
  rep(i, 0, n - 1) cin >> a[i];
  segtree<int, op, e> seg(a);
  while (m--) {
    int op, x, y;
    cin >> op;
    if (op == 1) {
      cin >> x >> y;
      seg.set(x - 1, y);
    } else if (op == 2) {
      cin >> x >> y;
      x--;
      cout << seg.prod(x, y) << endl;
    } else {
      cin >> x >> target;
      x--;
      cout << seg.max_right<f>(x) + 1 << endl;
    }
  }
  return 0;
}